digits = "996"

digits = list(digits)
for i in range(len(digits)):
    digits[i] = int(digits[i])
# 转换为整数数组

result = []  # 定义存储结果的函数

phone = {
    2: ['a', 'b', 'c'],
    3: ['d', 'e', 'f'],
    4: ['g', 'h', 'i'],
    5: ['j', 'k', 'l'],
    6: ['m', 'n', 'o'],
    7: ['p', 'q', 'r', 's'],
    8: ['t', 'u', 'v'],
    9: ['w', 'x', 'y', 'z']
}


def back(combination, next_digits):
    "参数为当前的组合和接下来要准备的数字"
    if len(next_digits) == 0:
        result.append(combination)
    else:
        for letter in phone[next_digits[0]]:
            back(combination + letter, next_digits[1:])  # 每次只取数组的第一个元素,然后返回删除第一个元素的新数组


if digits:
    back("", digits)  # 第一次传入空字符串的结果和完整的数组
print(result)
